package com.qf.ssm.controller;

import com.qf.ssm.dto.R;
import com.qf.ssm.pojo.UserRole;
import com.qf.ssm.service.UserRoleService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tests")
public class UserRoleController {

    private UserRoleService userRoleService;

    @Autowired
    public void setUserRoleService(UserRoleService userRoleService) {
        this.userRoleService = userRoleService;
    }

    @PostMapping("/test1")
    public R addUserRole(@RequestBody UserRole userRole){
        userRoleService.addUserRole(userRole);
        return R.setOK();
    }

    @PutMapping("/test1")
    public R updateUserRole(@RequestBody UserRole userRole){
        userRoleService.updateUserRole(userRole);
        return R.setOK();
    }

    @DeleteMapping("/test2")
    public R deleteUserRoleByIds(Long []ids){
        userRoleService.deleteUserRoleByIds(ids);
        return R.setOK();
    }

    @GetMapping("/tests")
    public R findAllUserRole(){
        List<UserRole> userRoleList = userRoleService.findAllUserRole();
        return R.setOK(userRoleList);

    }
}
